/*MyPhotoIndex Free Photo Organizer <www.myphotoindex.com>
  Copyright (C) <2006-2007>  <Asaf Yarkoni asaf@yarkoni.net>

  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.*/
using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Drawing.Design;
using MyPhotoIndex.Utilities;
using MyPhotoIndex.Interfaces;

namespace MyPhotoIndex.Plugins
{
    public class FacebookPluginSettings : IDynamicSetting
    {
        private static ISettingsManager m_settingsManager;
        private String m_lastUsedAlbumId;

        public FacebookPluginSettings()
        {

        }

        public override string ToString()
        {
            return "Facebook Plugin";
        }

        public static FacebookPluginSettings Default
        {
            get
            {
                return (FacebookPluginSettings)SettingsManager[typeof(FacebookPluginSettings)];
            }
        }

        public static ISettingsManager SettingsManager
        {
            get { return FacebookPluginSettings.m_settingsManager; }
            set { FacebookPluginSettings.m_settingsManager = value; }
        }

        [Category("Facebook Plugin")]
        [DisplayName("Set Extended permissions")]
        [Description("Set Extended permissions for Facebook to be used by MyPhotoIndex.")]
        [EditorAttribute(typeof(UIBoolBrowseEditor), typeof(UITypeEditor))]
        public Object ExtendedPermissions
        {
            get { return null; }
            set { }
        }

        [Category("Facebook Plugin")]
        [Browsable(false)]
        public String LastUsedAlbumId
        {
            get { return m_lastUsedAlbumId; }
            set { m_lastUsedAlbumId = value; }
        }

        //[Category("Facebook Plugin")]
        //[DisplayName("Upload Images as Friend images")]
        //public bool IsFriend
        //{
        //    get { return m_isFriend; }
        //    set { m_isFriend = value; }
        //}

        internal void Save()
        {
            SettingsManager.Save();
        }
    }

    class UIBoolBrowseEditor : UITypeEditor
    {
        public UIBoolBrowseEditor()
        {
            
        }

        public override bool GetPaintValueSupported(ITypeDescriptorContext context)
        {
            return true;
           // return base.GetPaintValueSupported(context);
        }

        public override void PaintValue(PaintValueEventArgs e)
        {
            e.Graphics.FillRectangle(System.Drawing.Brushes.White, e.Bounds);
        //    base.PaintValue(e);
        }

        public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
        {
          //  return base.GetEditStyle(context);
            
            return UITypeEditorEditStyle.Modal;
        }

        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            try
            {
                String url = String.Format("http://www.facebook.com/authorize.php?api_key={0}&v=1.0&ext_perm=photo_upload&popup=true", "650b150054e483ccb33c51844fdeb4ac");
                Browser browser = new Browser(url);
                browser.Size = new System.Drawing.Size(442, 564);
                browser.ShowDialog();

                return base.EditValue(context, provider, value);
            }
            catch (Exception ex)
            {
                Logger.Log(ex);
            }

            return null;
        }
    }
}
